/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2021-12-03 15:31:52
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-28 19:19:01
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\order-management\\services\\order-management.service.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */

import { Injectable, Injector } from '@angular/core';
import { EACacheService, ShipperBaseService } from '@shared';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class OrderManagementService extends ShipperBaseService {
  $api_get_getEnterpriseNetTransHis = `/api/mdc/enterpriseNetTransHis/getEnterpriseNetTransHis`;
  $api_get_catalogue_member = `/user?_allow_anonymous=true`;
  $api_get_bulkPage_list = `/api/sdc/goodsResourceOperate/listBulkPage`;
  // 据 手机号/姓名 查询 车队长/司机
  $api_get_getDriverInfo = `/api/mdc/cuc/user/getDriverInfo`;
  $api_del_driver = ``;
  // 获取货主企业列表
  public $api_getList = '/api/mdc/cuc/enterpriseInfo/cargoOwner/getList?_allow_anonymous=true';
  // 风险单：
  //  风险单列表查询
  $api_get_listRiskPage = `/api/sdc/billRiskOperate/listRiskPage`;
  //  风险单列表查询
  $api_get_listStatisticalStatus = `/api/sdc/billRiskOperate/listStatisticalStatus`;
  //  风险单详情查询
  $api_get_getRiskDetail = `/api/sdc/billRiskOperate/getRiskDetail`;
  //  风险单审核
  $api_get_listRisk_audit = `/api/sdc/billRiskOperate/audit`;
  //  查询整车订单列表
  $api_get_listWholePage = `/api/sdc/billOperate/listWholePage`;
  //  整车详情
  $api_get_getWholeBillDetail = `/api/sdc/billOperate/getWholeBillDetail`;
  // 根据车牌号查询车辆信息
  $api_get_getCarLicenseListByCarNo = `/api/mdc/cuc/carLicense/findCarLicenseByCarNo`;

  //  查询大宗订单列表
  $api_get_listBulkPage = `/api/sdc/billOperate/listBulkPage`;
  //  查看运费变更记录详情-整车
  $api_get_getChangeRecordWholeDetail = `/api/sdc/billFreightChangeRecord/getChangeRecordWholeDetail`;
  //  根据订单ID查看运费变更申请记录
  $api_get_listChangeApply = `/api/sdc/billFreightChangeApplication/listChangeApply`;
  //  变更运费页面-整车-整车
  $api_get_getFreightChangeWholeDetail = `/api/sdc/billFreightChangeApplication/getFreightChangeWholeDetail`;
  //  订单申请撤销
  $api_get_revokeChangeRecord = `/api/sdc/billFreightChangeApplication/revokeChangeRecord`;
  //  运费变更申请-整车
  $api_get_insertFreightChangeWhole = `/api/sdc/billFreightChangeApplication/insertOperateFreightChangeWhole`;
  //  取消订单
  $api_get_cancelAnOrder = `/api/sdc/billOperate/cancelAnOrder`;
  //  批量签收整车订单
  $api_get_batchSignWholeOrder = `/api/sdc/billOperate/batchSignWholeOrder`;
  //  批量签收大宗订单
  $api_get_batchSignBulkOrder = `/api/sdc/billOperate/batchSignBulkOrder`;
  //  大宗签收详情
  $api_get_getBulkSignForDetail = `/api/sdc/billOperate/getBulkSignForDetail`;
  //  整车签收详情
  $api_get_getWholeSignForDetail = `/api/sdc/billOperate/getWholeSignForDetail`;
  //  确认签收大宗订单
  $api_get_signBulkOrder = `/api/sdc/billOperate/signBulkOrder`;
  //  确认签收整车订单
  $api_get_signWholeOrder = `/api/sdc/billOperate/signWholeOrder`;
  // 上传图片
  public $api_upload_url = `/api/mdc/pbc/upload/multipartFile/file`;
  // 根据用户id查用户信息（注意：nickName才是用户名称）
  public $api_getUserDetailByAppUserId = `/api/mdc/cuc/userBasicInfo/get`;
  // 根据车辆id查车辆信息
  public $api_getCarLicenseByIds = `/api/mdc/cuc/carLicense/getCarLicenseByIds`;
  // 统计【整车】订单状态数量
  public $api_statisticalStatus = `/api/sdc/billOperate/getWholeStatistical`;
  // 统计【大宗】订单状态数量
  public $api_getBulkStatistical = `/api/sdc/billOperate/getBulkStatistical`;
  // 变更运费页面-大宗
  public $api_getFreightChangeBulkDetail = `/api/sdc/billFreightChangeApplication/getFreightChangeBulkDetail`;
  // 变更运费页面-大宗
  public $api_insertFreightChangeBulk = `/api/sdc/billFreightChangeApplication/insertFreightChangeBulk`;
  // 大宗详情
  public $api_getBulkBillDetail = `/api/sdc/billOperate/getBulkBillDetail`;
  // 查看运费变更记录详情-大宗
  public $api_getChangeRecordBulkDetail = `/api/sdc/billFreightChangeRecord/getChangeRecordBulkDetail`;
  // 查看运费变更记录详情-整车
  public $api_getChangeRecordWholeDetail = `/api/sdc/billFreightChangeRecord/getChangeRecordWholeDetail`;
  //运费变更申请计算费用-大宗
  $api_calculate_cost = `/api/sdc/billFreightChangeApplication/getBulkSurchargeDetail`;
  //运费变更申请计算费用-整车
  $api_getWholeSurchargeDetail = `/api/sdc/billFreightChangeApplication/getWholeSurchargeDetail`;
  //运费变更申请-大宗
  $api_change_bulk = `/api/sdc/billFreightChangeApplication/insertOperateFreightChangeBulk`;
  // 删除装卸货信息
  $api_delete_Wholedeletebatch = `/api/sdc/unLoadingPlace/deletebatch`;
  // 修改-大宗订单
  $api_set_modifyBulkOrder = `/api/sdc/billOperate/modifyBulkOrder`;
  // 修改-整车订单
  $api_set_modifyWholeOrder = `/api/sdc/billOperate/modifyWholeOrder`;
  // 批量修改网络货运人
  $api_set_updateEnterpriseInfoBatch = `/api/sdc/billOperate/updateEnterpriseInfoBatch`;
  // 批量修改附加费率
  $api_set_updateAdditionalRateBatch = `/api/sdc/billOperate/updateAdditionalRateBatch`;

  // 查询投诉列表
  $api_get_operate_listPage = `/api/sdc/complaint/operate/listPage`;
  // 获取投诉表详情
  $api_get_getComplaintDriverDetails = `/api/sdc/complaint/operate/getComplaintDriverDetails`;
  // 处理投诉
  $api_get_dealWithComplaint = `/api/sdc/complaint/operate/dealWithComplaint`;
  // 撤销投诉
  $api_get_canelComplaint = `/api/sdc/complaint/operate/canelComplaint`;

  // 批量修改车队长
  $api_get_updateCarCaptainBatch = `/api/sdc/billOperate/updateCarCaptainBatch`;
  // 根据手机号查询车队长/司机
  $api_get_getCarCaptainByMobile = `/api/mdc/userDriverExpand/getCarCaptainByMobile`;

  // 获取货主企业列表
  public $api_enterpriceList = '/api/mdc/cuc/enterpriseInfo/operate/enterpriceList';
  // 查询系统配置项
  public $api_get_config_item_page = '/api/mdc/pbc/sysConfigItem/list/page';

  // 查询单据审核
  public $api_get_billExamine_page = '/api/sdc/billExamine/listPage';
  // 单据审核查看凭证
  public $api_get_getCredentials = '/api/sdc/billExamine/getCredentials';
  // 单据审核
  public $api_get_billAudit = '/api/sdc/billExamine/billAudit';
  // 统计单据审核状态数量
  public $api_get_getAuditStatistical = '/api/sdc/billExamine/getAuditStatistical';
  // 修改单据审核
  public $api_get_updateBillExamine = '/api/sdc/billExamine/updateBillExamine';
  // 单据审核通过
  public $api_get_billAuditPass = '/api/sdc/billExamine/billAuditPassBatch';

  // 查询规则抽查列表
  public $api_get_listCompliancePage = '/api/sdc/BillComplianceSpotCheck/list/Page';
  // 规则抽查审批
  public $api_get_updateBillByCompliance = '/api/sdc/billOperate/updateBillByCompliance';
  // 获取规则抽查分类统计
  public $api_get_getComplianceStatisticalStatus = '/api/sdc/billOperate/getComplianceStatisticalStatus';

  // 货主端-货主查看评价（评价司机的）
  public $api_getBillEvaluateByShipper = '/api/sdc/billEvaluate/getBillEvaluateByShipper';
  // 货主端-货主查看评价（司机评价货主的）
  public $api_getBillEvaluateDriverByShipper = '/api/sdc/billEvaluate/getBillEvaluateDriverByShipper';

  // 获取订单退款申请表
  public $api_billRefundApplication_get = '/api/fcc/billRefundApplication/get';
  // 同意退款
  public $api_billRefundApplication_agreeRefund = '/api/fcc/billRefundApplication/agreeRefund';
  // 保存订单退款申请表
  public $api_billRefundApplication_save = '/api/fcc/billRefundApplication/save';

  // 批量修改费率-实时查看附加费
  public $api_searchAdditionalRateBatch = '/api/sdc/billOperate/searchAdditionalRateBatch';

  // 风险异常
  public $api_listBillComplianceAbnormalByBillId = '/api/sdc/billCompliance/listBillComplianceAbnormalByBillId';
  // 异常预警
  public $api_getAbnormalWarningByBillId = '/api/sdc/abnormalWarning/getAbnormalWarningByBillId';

  // 获取电子提/卸货单签章附件
  public $api_getBillGoodsEsignFile = '/api/sdc/billOperate/getBillGoodsEsignFile';
  // 生成提货单
  public $api_createBillTakeGoods = '/api/sdc/billOperate/createBillTakeGoods';
  // 生成卸货单-页面展示
  public $api_getBillDischargeGoodsVO = '/api/sdc/billOperate/getBillDischargeGoodsVO';
  // 生成提货单-页面展示
  public $api_getBillTakeGoodsVO = '/api/sdc/billOperate/getBillTakeGoodsVO';

  getDictByKey(dictKey: string) {
    const params = { dictKey: dictKey };
    return this.request(this.$api_getDictValue, params);
  }
  $api_get_risk_order_log = `/api/mdc/pbc/operationLogRecords/getOperationLogRecordsList`; // 获取货源的操作日志
  // 获取数据字典
  $api_getDictValue = `/api/mdc/pbc/dictItems/getDictValue`;
  // 获取轨迹
  $api_get_getTrajectory = `/api/sdc/billOperate/getTrajectoryByBillId`;
  // 重新获取轨迹
  $api_get_againGetBillTrajectoryByBillId = `/api/sdc/billOperate/againGetBillTrajectoryByBillId`;
  
  //  获取订单司机轨迹
  $api_get_getAppDriverPosition = `/api/sdc/billShipper/getAppDriverPosition`;
  //  查看申述记录
  $api_get_getOrderComplaintDetail = `/api/sdc/billOperate/getOrderComplaintDetail`;

  //  查询异常预警表
  $api_get_abnormalWarning = `/api/sdc/abnormalWarning/list/page`;
  $api_get_order_abnormalWarning = `/api/sdc/abnormalWarning/getAbnormalWarningByBillId`;

  //  异步导出运营后台大宗订单列表
  $api_get_asyncExportBulkList = `/api/sdc/billOperate/asyncExportBulkList`;
  //  异步导出运营后台整车订单列表
  $api_get_asyncExportWholeList = `/api/sdc/billOperate/asyncExportWholeList`;
  //  异步导出风险单导出
  $api_get_asyncExportRiskBillList = `/api/sdc/billRiskOperate/asyncExportRiskBillList`;
  //  异步导出合规抽查导出
  $api_get_asyncExportSpotCheckList = `/api/sdc/BillComplianceSpotCheck/asyncExportSpotCheckList`;
  //  异步导出单据审核导出
  $api_get_asyncExportExamineBillList = `/api/sdc/billExamine/asyncExportExamineBillList`;
  //  异步导出单据审核导出
  $api_abnormalWarning_asyncExport = `/api/sdc/abnormalWarning/asyncExport`;
  //  异步导出投诉管理导出
  $api_asyncExportComplaintListDrv = `/api/sdc/complaint/operate/asyncExportComplaintListDrv`;
  //操作日志
  public $api_get_log_list = `/api/mdc/pbc/operationLogRecords/getOperationLogRecordsList`;
  // 查看补充协议
  public $api_getSupplementaryAgreement = `/api/sdc/billShipper/getSupplementaryAgreement`;

  // 获取电子提货单签章附件
  public $api_getBillTakeEsignFile = `/api/sdc/billOperate/getBillTakeEsignFile`;
  // 获取电子卸货单签章附件
  public $api_getBillDischargeEsignFile = `/api/sdc/billOperate/getBillDischargeEsignFile`;
  // 预览卸货单
  public $api_getBillDischargeGoods = `/api/sdc/billOperate/getBillDischargeGoods`;
  // 预览提货单
  public $api_getBillTakeGoods = `/api/sdc/billOperate/getBillTakeGoods`;
  // 生成提/卸货单
  public $api_createBillEsignGoods = `/api/sdc/billOperate/createBillEsignGoods`;
  // 订单上报推送
  $api_manualOrderSubmission = '/api/sdc/billOperate/manualOrderSubmission';
  
  // 订单上报推送
  $api_deleteBatch = '/api/sdc/billShipper/deleteBatch';

  // 获取司机所有银行卡信息
  $api_getDriverBankInfoList= '/api/fcc/bankInfoDMC/getDriverBankInfoList';

  // // 生成卸货单
  // public $api_createBillDischargeGoods = `/api/sdc/billOperate/createBillDischargeGoods`;
  // // 生成提货单
  // public $api_createBillTakeGoods = `/api/sdc/billOperate/createBillTakeGoods`;
  /**
   * 根据企业ID，获取企业历史网络货运人
   * @returns
   */
  getNetworkFreightForwarderHistory(params: any) {
    const param = {
      enterpriseIds: params.enterpriseInfoIds
    };
    return this.request(this.$api_get_getEnterpriseNetTransHis, param).pipe(
      map((res: any) => {
        if (!res) {
          return [];
        }
        const list = res.map((item: any) => ({
          label: item.networkTransporterName,
          value: item.networkTransporterId
        }));
        return [{ value: '', label: '全部' }, ...list];
      })
    );
  }
  /**
   * 获取车型、车长字典数据
   * @returns
   */
  getDictOptions(params = {}) {
    return this.request(this.$api_getDictValue, params).pipe(
      map((res: any) => {
        if (!res) {
          return [];
        }
        const obj = [];
        obj.push({ label: '不限', value: '999' });
        return [...obj, ...res];
      })
    );
  }
  constructor(public injector: Injector) {
    super(injector);
  }
  public reviewPDF(url: string) {
    if (!url) {
      return;
    }
    this.openURL(url);
    // const uA = window.navigator.userAgent; // 判断浏览器内核
    // const isIE =
    //   /msie\s|trident\/|edge\//i.test(uA) &&
    //   !!('uniqueID' in document || 'documentMode' in document || 'ActiveXObject' in window || 'MSInputMethodContext' in window);
    // const objectUrl = url;
    // const a = document.createElement('a');
    // document.body.appendChild(a);
    // a.href = objectUrl;
    // a.download = '附件.pdf';
    // if (isIE) {
    //   // 兼容IE11无法触发下载的问题
    //   (navigator as any).msSaveBlob(url, a.download);
    // } else {
    //   a.click();
    // }
    // a.remove();
  }
}
